package pl.pyjter;

import javax.swing.*;
import java.awt.*;
import java.util.List;

public class LibraryApplication {

	public static void main(String[] args) throws Throwable {
		JFrame frame = new JFrame("Library");
		JPanel contentPane = (JPanel) frame.getContentPane();
		HibernateTableModel<Author> tbMod = new HibernateTableModel<>(Author.class);
//		HibernateTableModel<Book> tbMod = new HibernateTableModel<>(Book.class);
//		HibernateTableModel<Publisher> tbMod = new HibernateTableModel<>(Publisher.class);
		
		JTable tbl = new JTable(tbMod);
		contentPane.add(new JScrollPane(tbl));
		LibraryHibImpl library = new LibraryHibImpl();

//		List<Book> books = library.getObjects("Book");
//		for(Book book : books) {
//			tbMod.insertRow(book);
//		}
		
		List<Author> authors = library.getObjects("Author");		
		for(Author author : authors) {
			tbMod.insertRow(author);
		}
		
		tbMod.deleteRow(3);
		
//		List<Publisher> publishers = library.getObjects("Publisher");		
//		for(Publisher publisher : publishers) {
//			tbMod.insertRow(publisher);
//		}
		frame.setSize(700, 300);
		frame.setLocation(100, 100);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}

}
